package com.daliu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {
    //定义切入点表达式
    @Pointcut("execution(* com.daliu.service.*.*.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp){
        Object result = null;
        long endTime=0;
        long startTime=0;
        long time;
        try {
            startTime = System.currentTimeMillis();
            // 让原方法执行  method.invoke()
            result = pjp.proceed();
            endTime = System.currentTimeMillis();
            time = (endTime-startTime);
            System.out.println("方法耗时"+time);
        } catch (Throwable throwable) {
            //throwable.printStackTrace();
            time = (endTime-startTime);
            System.out.println("方法耗时"+time);
        }finally {

        }
        return result;
    }

}
